package face;

import java.util.Stack;

/**
 * @author spf
 * @date 2024/5/21
 * @time 16:50
 */

/**
 * 如何用栈实现队列
 * @param <T>
 */
public class StackToQueue<T> {

    private Stack<T> stackIn;

    private Stack<T> stackOut;

    public StackToQueue(){
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void enqueue(T element){
        stackIn.push(element);
    }

    public T dequeue(){
        if (stackOut.isEmpty()){
            while (!stackIn.isEmpty()){
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.pop();
    }

    public boolean isEmpty(){
        return stackIn.isEmpty() && stackOut.isEmpty();
    }

}
